package net.wisos.opn.search;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrServer;

public class MultiCoreSearchServerFactory {
	private static Logger logger = Logger.getLogger(SearchServerFactory.class);
	private static Map<String, SolrServer> searchServerMap = Collections
			.synchronizedMap(new HashMap<String, SolrServer>());
	private EmbeddedServerContainer embeddedServerContainer;

	public SolrServer getSearchServer(String searchName) {
		SolrServer solrServer = null;
		if (!searchServerMap.containsKey(searchName)) {
			solrServer = embeddedServerContainer.getSolrCore(searchName);
			if (solrServer != null)
				searchServerMap.put(searchName, solrServer);
		}
		logger.info("搜索服务:" + searchName);
		return searchServerMap.get(searchName);
	}

	public EmbeddedServerContainer getEmbeddedServerContainer() {
		return embeddedServerContainer;
	}

	public void setEmbeddedServerContainer(
			EmbeddedServerContainer embeddedServerContainer) {
		this.embeddedServerContainer = embeddedServerContainer;
	}
}
